package com.news.gpb.dao;

import com.news.gpb.entity.Card;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.sql.Date;
import java.util.List;

@Repository
public interface CardDao {

    @Select("select count(*) from cards where user_id=#{user_id}")
    Integer countCollect(@Param("user_id") int user_id);

    @Select("select * from cards where user_id=#{user_id} order by card_date desc")
    List<Card> getCard(@Param("user_id")int user_id);

    @Select("select * from cards where user_id=#{user_id} ORDER BY card_review desc LIMIT 10")
    List<Card> reviewCard(@Param("user_id")int user_id);

    @Insert("insert into cards(user_id,news_id,card_question,card_answer,card_text) values(#{card.user_id},#{card.news_id},#{card.card_question},#{card.card_answer},#{card.card_text})")
    @Options(useGeneratedKeys = true,keyProperty = "card.card_id",keyColumn = "card_id")
    Integer makeCard(@Param("card")Card card);

    @Delete("delete from cards where card_id=#{card_id}")
    Integer removeCard(@Param("card_id")int card_id);

    @Update("update cards set card_review =card_review+1 where card_id=#{card_id}")
    Integer updateCard(@Param("card_id")int card_id);
}
